package threading;

/**
 * @author krystal
 * @date 2022/11/24 16:02
 */
//这个类，就作为一个”实例类“
//要求singleton只有一个实例
class Singleton{
    private static Singleton instance=new Singleton();

    public static Singleton getInstance(){
        return instance;
    }

    //把构造方法设为private，此时在类的外边，就无法继续new实例了
    private Singleton(){

    }
}

public class Demo20 {
    public static void main(String[] args) {
        Singleton instance=Singleton.getInstance();
    }
}
